//
//  GenericsAndNullabilityTest.h
//  test_simple_project
//
//  Objective-C泛型和可空性注解测试文件
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

// 泛型类声明 - 测试Objective-C泛型语法
@interface GenericContainer<ObjectType> : NSObject

@property (strong, nonatomic) NSMutableArray<ObjectType> *items;
@property (nullable, strong, nonatomic) ObjectType currentItem;
@property (readonly, strong, nonatomic) NSArray<ObjectType> *allItems;

- (instancetype)initWithCapacity:(NSUInteger)capacity;
- (void)addItem:(ObjectType)item;
- (void)addItems:(NSArray<ObjectType> *)items;
- (nullable ObjectType)itemAtIndex:(NSUInteger)index;
- (void)removeItem:(ObjectType)item;
- (NSUInteger)count;

// 泛型方法
- (NSArray<ObjectType> *)filteredItemsUsingBlock:(BOOL (^)(ObjectType item))block;
- (void)enumerateItemsUsingBlock:(void (^)(ObjectType item, NSUInteger index, BOOL *stop))block;

@end

// 泛型协议声明
@protocol GenericDataSource <NSObject>

- (NSUInteger)numberOfItems;
- (nullable id)itemAtIndex:(NSUInteger)index;

@optional
- (nullable NSString *)titleForItemAtIndex:(NSUInteger)index;

@end

// 多个泛型参数的类
@interface GenericKeyValueStore<KeyType, ValueType> : NSObject

@property (strong, nonatomic) NSMutableDictionary<KeyType, ValueType> *storage;

- (void)setValue:(ValueType)value forKey:(KeyType)key;
- (nullable ValueType)valueForKey:(KeyType)key;
- (NSArray<KeyType> *)allKeys;
- (NSArray<ValueType> *)allValues;

@end

// 可空性注解测试类
@interface NullabilityTestClass : NSObject

// 基本可空性注解
@property (nullable, strong, nonatomic) NSString *optionalString;
@property (nonnull, strong, nonatomic) NSString *requiredString;
@property (null_unspecified, strong, nonatomic) NSString *unspecifiedString;

// 数组和字典的可空性
@property (nullable, strong, nonatomic) NSArray<NSString *> *optionalArray;
@property (nonnull, strong, nonatomic) NSArray<NSString *> *requiredArray;
@property (nullable, strong, nonatomic) NSDictionary<NSString *, NSNumber *> *optionalDictionary;

// 块的可空性注解
@property (nullable, copy, nonatomic) void (^optionalBlock)(NSString *input);
@property (nonnull, copy, nonatomic) NSString * (^requiredBlock)(NSString *input);

// 方法参数和返回值的可空性
- (nullable NSString *)processOptionalString:(nullable NSString *)input;
- (nonnull NSString *)processRequiredString:(nonnull NSString *)input;
- (nullable NSArray<NSString *> *)filterStrings:(nonnull NSArray<NSString *> *)strings 
                                     withBlock:(nonnull BOOL (^)(NSString *string))filterBlock;

// 带有多个可空性参数的方法
- (void)complexMethodWithRequired:(nonnull NSString *)required 
                         optional:(nullable NSString *)optional
                      unspecified:(null_unspecified NSString *)unspecified
                       completion:(nullable void (^)(NSString *result, NSError *error))completion;

@end

// 泛型与可空性结合的测试类
@interface GenericNullabilityTest<ItemType> : NSObject

@property (nullable, strong, nonatomic) NSArray<ItemType> *optionalItems;
@property (nonnull, strong, nonatomic) NSMutableArray<ItemType> *requiredItems;

- (void)addOptionalItem:(nullable ItemType)item;
- (void)addRequiredItem:(nonnull ItemType)item;
- (nullable ItemType)firstOptionalItem;
- (nonnull ItemType)firstRequiredItemWithDefault:(nonnull ItemType)defaultItem;

@end

// 协议中的泛型和可空性
@protocol GenericNullableProtocol <NSObject>

- (nullable id)optionalDataForKey:(nonnull NSString *)key;
- (nonnull NSArray *)requiredDataArray;
- (void)processData:(nullable id)data completion:(nonnull void (^)(BOOL success))completion;

@end

// 类型别名与泛型
typedef NSArray<NSString *> *StringArray;
typedef NSDictionary<NSString *, NSNumber *> *StringToNumberDict;
typedef void (^CompletionBlock)(BOOL success, NSError * _Nullable error);

// 全局函数的可空性注解
NSString * _Nullable CreateOptionalString(NSString * _Nonnull input);
NSArray<NSString *> * _Nonnull CreateStringArray(NSUInteger count);
void ProcessWithCompletion(NSString * _Nonnull input, CompletionBlock _Nonnull completion);

NS_ASSUME_NONNULL_END